/*
* acooly.cn Inc.
* Copyright (c) 2017 All Rights Reserved.
* create by ouwen
* date:2017-09-20
*/
package com.yiji.fintech.musfinance.web;

import com.acooly.core.common.web.AbstractJQueryEntityController;
import com.yiji.fintech.musfinance.base.enums.CardTypeEnum;
import com.yiji.fintech.musfinance.base.enums.PersonalCorporateTypeEnum;
import com.yiji.fintech.musfinance.base.enums.SubTransactionTypeEnum;
import com.yiji.fintech.musfinance.base.enums.TransactionTypeEnum;
import com.yiji.fintech.musfinance.common.enums.StatusEnum;
import com.yiji.fintech.musfinance.common.utils.cache.CacheConstant;
import com.yiji.fintech.musfinance.common.utils.cache.CacheService;
import com.yiji.fintech.musfinance.entity.BusinessRule;
import com.yiji.fintech.musfinance.service.BusinessRuleService;
import com.yiji.fintech.musfinance.service.InstBankService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * center_business_rule 管理控制器
 * 
 * @author ouwen
 * Date: 2017-09-20 23:38:05
 */
@Controller
@RequestMapping(value = "/manage/businessrule/businessRule")
public class BusinessRuleManagerController extends AbstractJQueryEntityController<BusinessRule, BusinessRuleService> {

	@Autowired
	private InstBankService instBankService;
	@Autowired
	private CacheService cacheService;

	{
		allowMapping = "*";
	}
	@Override
	public String edit(HttpServletRequest request, HttpServletResponse response, Model model) {
		String partnerId = request.getParameter("partnerId");
		model.addAttribute("partnerId",partnerId);
		return super.edit(request, response, model);
	}
	@Override
	public String create(HttpServletRequest request, HttpServletResponse response, Model model) {
		String partnerId = request.getParameter("partnerId");
		model.addAttribute("partnerId",partnerId);
		return super.create(request, response, model);
	}

	@Override
	protected BusinessRule doSave(HttpServletRequest request, HttpServletResponse response, Model model, boolean isCreate) throws Exception {
		BusinessRule businessRule = super.doSave(request, response, model, isCreate);
		cacheService.doUpdateMutiCache(CacheConstant.CENTER_BUSINESS_RULE_MUTICACHE,BusinessRuleService.class);//更新能力多级缓存
		return businessRule;
	}

	@Override
	protected void referenceData(HttpServletRequest request, Map<String, Object> model) {
		model.put("allTransactionTypes", TransactionTypeEnum.mapping());
		model.put("allSubTransactionTypes", SubTransactionTypeEnum.mapping());
		model.put("allPersonalCorporateTypes", PersonalCorporateTypeEnum.mapping());
		model.put("allDebitCreditTypes", CardTypeEnum.mapping());
		model.put("allCardTypes", CardTypeEnum.mapping());
		model.put("allStatuss", StatusEnum.mapping());
		List<Map<String,Object>> allBank = instBankService.getAllInstBank();
		model.put("allBank", allBank);
	}

}
